<template>
  <div class="common-warp wh100 warp-bg">
    <div class="noo">
      <a-card title="钱包类型信息">
        <!-- <template #extra><a href="#">more</a></template> -->
        <a-form ref="formRef" :model="state.form" :rules=rules>
          <a-form-item label="类型名称" name="name">
            <a-input v-model:value="state.form.name" />
          </a-form-item>

          <a-form-item label="默认金额" name="defaultCash">
            <a-input-number v-model:value="state.form.defaultCash" style="width: 100%;" />
          </a-form-item>
          <a-form-item label="默认津贴" name="defaultAllowance">
            <a-input-number v-model:value="state.form.defaultAllowance" style="width: 100%;" />
          </a-form-item>
          <a-form-item label="默认补贴" name="defaultSubsidy">
            <a-input-number v-model:value="state.form.defaultSubsidy" style="width: 100%;" />
          </a-form-item>
          <a-form-item label="日限次" name="dayLimitTimes">
            <a-input-number v-model:value="state.form.dayLimitTimes" style="width: 100%;" />
          </a-form-item>
          <a-form-item label="周限次" name="weekLimitTimes">
            <a-input-number v-model:value="state.form.weekLimitTimes" style="width: 100%;" />
          </a-form-item>
          <a-form-item label="月限次" name="monthLimitTimes">
            <a-input-number v-model:value="state.form.monthLimitTimes" style="width: 100%;" />
          </a-form-item>

        </a-form>
      </a-card>
    </div>
    <a-button type="primary" block @click="confirm(formRef)">提交</a-button>
  </div>
</template>

<script lang='ts' setup>
import { ref, reactive, onMounted, } from 'vue';
import { useRouter } from 'vue-router'
import { usePosWalletCategoryCreateApi } from '@/api/index'
import { message } from 'ant-design-vue';

const router = useRouter()
const formRef = ref();

const rules = {
  name: [{ required: true, message: '请输入钱包类型名称', trigger: 'change' }],
};

const useContent = () => {
  return {
    name: '',
    defaultAllowance: 100,
    defaultCash: 100,
    defaultSubsidy: 100,
    dayLimitTimes: 21,
    weekLimitTimes: 21,
    monthLimitTimes: 21,
  }
}

const state = reactive({
  form: useContent()
})

//提交
const confirm = (formRef: any) => {
  if (!formRef) return;
  formRef.validate().then(async () => {
    await usePosWalletCategoryCreateApi(state.form)
    message.success("操作成功",2);
    setTimeout(() => {
      router.push({ name: 'PosWalletCategory' })
    }, 2300)
  })
};

onMounted(() => {
  document.title = '新增'
})

</script>
<style scoped lang='less'>
.noo {
  height: calc(100vh - 56px);
  overflow-y: scroll;

  :deep(.ant-form-item-label) {
    padding: 0 !important;
  }

  :deep(.ant-card-body) {
    padding: 4px 12px !important;
  }

  :deep(.ant-card-head) {
    padding: 12px !important;
  }

  :deep(.ant-form-item) {
    margin-bottom: 12px !important;
  }

}
</style>